//
//  HZL_StoryCollectionTabelViewCell.m
//  B_Project
//
//  Created by 胡佳俊 on 15/11/28.
//  Copyright © 2015年 HZL. All rights reserved.
//

#import "HZL_StoryCollectionTabelViewCell.h"
#import "HZL_StoryItemCollectionViewCell.h"
@interface HZL_StoryCollectionTabelViewCell ()
@property (nonatomic, retain)UICollectionViewFlowLayout *layout;

@end
@implementation HZL_StoryCollectionTabelViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}


- (void)createView
{
    self.layout = [[UICollectionViewFlowLayout alloc]init];
    
    
//#warning 问题1:tableviewcell中 init创建布局为系统默认(320, 530) 设置frame时取window宽度
    //创建collectionView
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.layout];
    //滑动视图距离根视图内容边界
    self.collectionView.contentInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.collectionView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    [self.contentView addSubview:self.collectionView];
    
    //collectionView 注册cell
    [self.collectionView registerClass:[HZL_StoryItemCollectionViewCell class] forCellWithReuseIdentifier:@"StoryItemitem"];
    
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.collectionView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    [self.collectionView reloadData];

    
    self.layout.itemSize = CGSizeMake(( [UIScreen mainScreen].bounds.size.width - 30) / 2, 250);
    //列间距
    self.layout.minimumLineSpacing = 10;
    //行间距
    self.layout.minimumInteritemSpacing = 10;
    
    self.collectionView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 550);
    
}

- (void)setDelegate:(id<UICollectionViewDelegate>)delegate
{
    self.collectionView.delegate = delegate;
}
- (void)setDataSource:(id<UICollectionViewDataSource>)dataSource
{
    self.collectionView.dataSource = dataSource;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
